﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using YuuzleComic.IDAL;
using YuuzleComic.DBUtility;//Please add references
namespace YuuzleComic.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:cjxm
	/// </summary>
	public partial class cjxm:Icjxm
	{
		public cjxm()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("id", "cjxm"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from cjxm");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(YuuzleComic.Model.cjxm model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into cjxm(");
			strSql.Append("xmmc,xmfd,picxz,xmsx,cjurl,fnbody,fnfg,fnid,fnmc,mhurl,mhbody,mhmc,mhtp,mhtpurl,mhzz,mhjs,mhzt,mhfg,mhzj,wj,lz,mhzjid,zjurl,zjbody,zjsx,zjfy,zjtpurlsx,zjtpsl,zjtpsurl,zjtpurl,gxurl,gxbody,gxfg,gxmc,gxid)");
			strSql.Append(" values (");
			strSql.Append("@xmmc,@xmfd,@picxz,@xmsx,@cjurl,@fnbody,@fnfg,@fnid,@fnmc,@mhurl,@mhbody,@mhmc,@mhtp,@mhtpurl,@mhzz,@mhjs,@mhzt,@mhfg,@mhzj,@wj,@lz,@mhzjid,@zjurl,@zjbody,@zjsx,@zjfy,@zjtpurlsx,@zjtpsl,@zjtpsurl,@zjtpurl,@gxurl,@gxbody,@gxfg,@gxmc,@gxid)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@xmmc", SqlDbType.VarChar,255),
					new SqlParameter("@xmfd", SqlDbType.Bit,1),
					new SqlParameter("@picxz", SqlDbType.Bit,1),
					new SqlParameter("@xmsx", SqlDbType.Int,4),
					new SqlParameter("@cjurl", SqlDbType.VarChar,255),
					new SqlParameter("@fnbody", SqlDbType.Text),
					new SqlParameter("@fnfg", SqlDbType.Text),
					new SqlParameter("@fnid", SqlDbType.Text),
					new SqlParameter("@fnmc", SqlDbType.Text),
					new SqlParameter("@mhurl", SqlDbType.VarChar,255),
					new SqlParameter("@mhbody", SqlDbType.Text),
					new SqlParameter("@mhmc", SqlDbType.Text),
					new SqlParameter("@mhtp", SqlDbType.Text),
					new SqlParameter("@mhtpurl", SqlDbType.Text),
					new SqlParameter("@mhzz", SqlDbType.VarChar,255),
					new SqlParameter("@mhjs", SqlDbType.Text),
					new SqlParameter("@mhzt", SqlDbType.Text),
					new SqlParameter("@mhfg", SqlDbType.Text),
					new SqlParameter("@mhzj", SqlDbType.Text),
					new SqlParameter("@wj", SqlDbType.Text),
					new SqlParameter("@lz", SqlDbType.Text),
					new SqlParameter("@mhzjid", SqlDbType.Text),
					new SqlParameter("@zjurl", SqlDbType.VarChar,255),
					new SqlParameter("@zjbody", SqlDbType.Text),
					new SqlParameter("@zjsx", SqlDbType.Int,4),
					new SqlParameter("@zjfy", SqlDbType.VarChar,50),
					new SqlParameter("@zjtpurlsx", SqlDbType.Int,4),
					new SqlParameter("@zjtpsl", SqlDbType.Text),
					new SqlParameter("@zjtpsurl", SqlDbType.Text),
					new SqlParameter("@zjtpurl", SqlDbType.Text),
					new SqlParameter("@gxurl", SqlDbType.Text),
					new SqlParameter("@gxbody", SqlDbType.Text),
					new SqlParameter("@gxfg", SqlDbType.Text),
					new SqlParameter("@gxmc", SqlDbType.Text),
					new SqlParameter("@gxid", SqlDbType.Text)};
			parameters[0].Value = model.xmmc;
			parameters[1].Value = model.xmfd;
			parameters[2].Value = model.picxz;
			parameters[3].Value = model.xmsx;
			parameters[4].Value = model.cjurl;
			parameters[5].Value = model.fnbody;
			parameters[6].Value = model.fnfg;
			parameters[7].Value = model.fnid;
			parameters[8].Value = model.fnmc;
			parameters[9].Value = model.mhurl;
			parameters[10].Value = model.mhbody;
			parameters[11].Value = model.mhmc;
			parameters[12].Value = model.mhtp;
			parameters[13].Value = model.mhtpurl;
			parameters[14].Value = model.mhzz;
			parameters[15].Value = model.mhjs;
			parameters[16].Value = model.mhzt;
			parameters[17].Value = model.mhfg;
			parameters[18].Value = model.mhzj;
			parameters[19].Value = model.wj;
			parameters[20].Value = model.lz;
			parameters[21].Value = model.mhzjid;
			parameters[22].Value = model.zjurl;
			parameters[23].Value = model.zjbody;
			parameters[24].Value = model.zjsx;
			parameters[25].Value = model.zjfy;
			parameters[26].Value = model.zjtpurlsx;
			parameters[27].Value = model.zjtpsl;
			parameters[28].Value = model.zjtpsurl;
			parameters[29].Value = model.zjtpurl;
			parameters[30].Value = model.gxurl;
			parameters[31].Value = model.gxbody;
			parameters[32].Value = model.gxfg;
			parameters[33].Value = model.gxmc;
			parameters[34].Value = model.gxid;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(YuuzleComic.Model.cjxm model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update cjxm set ");
			strSql.Append("xmmc=@xmmc,");
			strSql.Append("xmfd=@xmfd,");
			strSql.Append("picxz=@picxz,");
			strSql.Append("xmsx=@xmsx,");
			strSql.Append("cjurl=@cjurl,");
			strSql.Append("fnbody=@fnbody,");
			strSql.Append("fnfg=@fnfg,");
			strSql.Append("fnid=@fnid,");
			strSql.Append("fnmc=@fnmc,");
			strSql.Append("mhurl=@mhurl,");
			strSql.Append("mhbody=@mhbody,");
			strSql.Append("mhmc=@mhmc,");
			strSql.Append("mhtp=@mhtp,");
			strSql.Append("mhtpurl=@mhtpurl,");
			strSql.Append("mhzz=@mhzz,");
			strSql.Append("mhjs=@mhjs,");
			strSql.Append("mhzt=@mhzt,");
			strSql.Append("mhfg=@mhfg,");
			strSql.Append("mhzj=@mhzj,");
			strSql.Append("wj=@wj,");
			strSql.Append("lz=@lz,");
			strSql.Append("mhzjid=@mhzjid,");
			strSql.Append("zjurl=@zjurl,");
			strSql.Append("zjbody=@zjbody,");
			strSql.Append("zjsx=@zjsx,");
			strSql.Append("zjfy=@zjfy,");
			strSql.Append("zjtpurlsx=@zjtpurlsx,");
			strSql.Append("zjtpsl=@zjtpsl,");
			strSql.Append("zjtpsurl=@zjtpsurl,");
			strSql.Append("zjtpurl=@zjtpurl,");
			strSql.Append("gxurl=@gxurl,");
			strSql.Append("gxbody=@gxbody,");
			strSql.Append("gxfg=@gxfg,");
			strSql.Append("gxmc=@gxmc,");
			strSql.Append("gxid=@gxid");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@xmmc", SqlDbType.VarChar,255),
					new SqlParameter("@xmfd", SqlDbType.Bit,1),
					new SqlParameter("@picxz", SqlDbType.Bit,1),
					new SqlParameter("@xmsx", SqlDbType.Int,4),
					new SqlParameter("@cjurl", SqlDbType.VarChar,255),
					new SqlParameter("@fnbody", SqlDbType.Text),
					new SqlParameter("@fnfg", SqlDbType.Text),
					new SqlParameter("@fnid", SqlDbType.Text),
					new SqlParameter("@fnmc", SqlDbType.Text),
					new SqlParameter("@mhurl", SqlDbType.VarChar,255),
					new SqlParameter("@mhbody", SqlDbType.Text),
					new SqlParameter("@mhmc", SqlDbType.Text),
					new SqlParameter("@mhtp", SqlDbType.Text),
					new SqlParameter("@mhtpurl", SqlDbType.Text),
					new SqlParameter("@mhzz", SqlDbType.VarChar,255),
					new SqlParameter("@mhjs", SqlDbType.Text),
					new SqlParameter("@mhzt", SqlDbType.Text),
					new SqlParameter("@mhfg", SqlDbType.Text),
					new SqlParameter("@mhzj", SqlDbType.Text),
					new SqlParameter("@wj", SqlDbType.Text),
					new SqlParameter("@lz", SqlDbType.Text),
					new SqlParameter("@mhzjid", SqlDbType.Text),
					new SqlParameter("@zjurl", SqlDbType.VarChar,255),
					new SqlParameter("@zjbody", SqlDbType.Text),
					new SqlParameter("@zjsx", SqlDbType.Int,4),
					new SqlParameter("@zjfy", SqlDbType.VarChar,50),
					new SqlParameter("@zjtpurlsx", SqlDbType.Int,4),
					new SqlParameter("@zjtpsl", SqlDbType.Text),
					new SqlParameter("@zjtpsurl", SqlDbType.Text),
					new SqlParameter("@zjtpurl", SqlDbType.Text),
					new SqlParameter("@gxurl", SqlDbType.Text),
					new SqlParameter("@gxbody", SqlDbType.Text),
					new SqlParameter("@gxfg", SqlDbType.Text),
					new SqlParameter("@gxmc", SqlDbType.Text),
					new SqlParameter("@gxid", SqlDbType.Text),
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = model.xmmc;
			parameters[1].Value = model.xmfd;
			parameters[2].Value = model.picxz;
			parameters[3].Value = model.xmsx;
			parameters[4].Value = model.cjurl;
			parameters[5].Value = model.fnbody;
			parameters[6].Value = model.fnfg;
			parameters[7].Value = model.fnid;
			parameters[8].Value = model.fnmc;
			parameters[9].Value = model.mhurl;
			parameters[10].Value = model.mhbody;
			parameters[11].Value = model.mhmc;
			parameters[12].Value = model.mhtp;
			parameters[13].Value = model.mhtpurl;
			parameters[14].Value = model.mhzz;
			parameters[15].Value = model.mhjs;
			parameters[16].Value = model.mhzt;
			parameters[17].Value = model.mhfg;
			parameters[18].Value = model.mhzj;
			parameters[19].Value = model.wj;
			parameters[20].Value = model.lz;
			parameters[21].Value = model.mhzjid;
			parameters[22].Value = model.zjurl;
			parameters[23].Value = model.zjbody;
			parameters[24].Value = model.zjsx;
			parameters[25].Value = model.zjfy;
			parameters[26].Value = model.zjtpurlsx;
			parameters[27].Value = model.zjtpsl;
			parameters[28].Value = model.zjtpsurl;
			parameters[29].Value = model.zjtpurl;
			parameters[30].Value = model.gxurl;
			parameters[31].Value = model.gxbody;
			parameters[32].Value = model.gxfg;
			parameters[33].Value = model.gxmc;
			parameters[34].Value = model.gxid;
			parameters[35].Value = model.id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from cjxm ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from cjxm ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public YuuzleComic.Model.cjxm GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,xmmc,xmfd,picxz,xmsx,cjurl,fnbody,fnfg,fnid,fnmc,mhurl,mhbody,mhmc,mhtp,mhtpurl,mhzz,mhjs,mhzt,mhfg,mhzj,wj,lz,mhzjid,zjurl,zjbody,zjsx,zjfy,zjtpurlsx,zjtpsl,zjtpsurl,zjtpurl,gxurl,gxbody,gxfg,gxmc,gxid from cjxm ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			YuuzleComic.Model.cjxm model=new YuuzleComic.Model.cjxm();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				model.xmmc=ds.Tables[0].Rows[0]["xmmc"].ToString();
				if(ds.Tables[0].Rows[0]["xmfd"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["xmfd"].ToString()=="1")||(ds.Tables[0].Rows[0]["xmfd"].ToString().ToLower()=="true"))
					{
						model.xmfd=true;
					}
					else
					{
						model.xmfd=false;
					}
				}
				if(ds.Tables[0].Rows[0]["picxz"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["picxz"].ToString()=="1")||(ds.Tables[0].Rows[0]["picxz"].ToString().ToLower()=="true"))
					{
						model.picxz=true;
					}
					else
					{
						model.picxz=false;
					}
				}
				if(ds.Tables[0].Rows[0]["xmsx"].ToString()!="")
				{
					model.xmsx=int.Parse(ds.Tables[0].Rows[0]["xmsx"].ToString());
				}
				model.cjurl=ds.Tables[0].Rows[0]["cjurl"].ToString();
				model.fnbody=ds.Tables[0].Rows[0]["fnbody"].ToString();
				model.fnfg=ds.Tables[0].Rows[0]["fnfg"].ToString();
				model.fnid=ds.Tables[0].Rows[0]["fnid"].ToString();
				model.fnmc=ds.Tables[0].Rows[0]["fnmc"].ToString();
				model.mhurl=ds.Tables[0].Rows[0]["mhurl"].ToString();
				model.mhbody=ds.Tables[0].Rows[0]["mhbody"].ToString();
				model.mhmc=ds.Tables[0].Rows[0]["mhmc"].ToString();
				model.mhtp=ds.Tables[0].Rows[0]["mhtp"].ToString();
				model.mhtpurl=ds.Tables[0].Rows[0]["mhtpurl"].ToString();
				model.mhzz=ds.Tables[0].Rows[0]["mhzz"].ToString();
				model.mhjs=ds.Tables[0].Rows[0]["mhjs"].ToString();
				model.mhzt=ds.Tables[0].Rows[0]["mhzt"].ToString();
				model.mhfg=ds.Tables[0].Rows[0]["mhfg"].ToString();
				model.mhzj=ds.Tables[0].Rows[0]["mhzj"].ToString();
				model.wj=ds.Tables[0].Rows[0]["wj"].ToString();
				model.lz=ds.Tables[0].Rows[0]["lz"].ToString();
				model.mhzjid=ds.Tables[0].Rows[0]["mhzjid"].ToString();
				model.zjurl=ds.Tables[0].Rows[0]["zjurl"].ToString();
				model.zjbody=ds.Tables[0].Rows[0]["zjbody"].ToString();
				if(ds.Tables[0].Rows[0]["zjsx"].ToString()!="")
				{
					model.zjsx=int.Parse(ds.Tables[0].Rows[0]["zjsx"].ToString());
				}
				model.zjfy=ds.Tables[0].Rows[0]["zjfy"].ToString();
				if(ds.Tables[0].Rows[0]["zjtpurlsx"].ToString()!="")
				{
					model.zjtpurlsx=int.Parse(ds.Tables[0].Rows[0]["zjtpurlsx"].ToString());
				}
				model.zjtpsl=ds.Tables[0].Rows[0]["zjtpsl"].ToString();
				model.zjtpsurl=ds.Tables[0].Rows[0]["zjtpsurl"].ToString();
				model.zjtpurl=ds.Tables[0].Rows[0]["zjtpurl"].ToString();
				model.gxurl=ds.Tables[0].Rows[0]["gxurl"].ToString();
				model.gxbody=ds.Tables[0].Rows[0]["gxbody"].ToString();
				model.gxfg=ds.Tables[0].Rows[0]["gxfg"].ToString();
				model.gxmc=ds.Tables[0].Rows[0]["gxmc"].ToString();
				model.gxid=ds.Tables[0].Rows[0]["gxid"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,xmmc,xmfd,picxz,xmsx,cjurl,fnbody,fnfg,fnid,fnmc,mhurl,mhbody,mhmc,mhtp,mhtpurl,mhzz,mhjs,mhzt,mhfg,mhzj,wj,lz,mhzjid,zjurl,zjbody,zjsx,zjfy,zjtpurlsx,zjtpsl,zjtpsurl,zjtpurl,gxurl,gxbody,gxfg,gxmc,gxid ");
			strSql.Append(" FROM cjxm ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,xmmc,xmfd,picxz,xmsx,cjurl,fnbody,fnfg,fnid,fnmc,mhurl,mhbody,mhmc,mhtp,mhtpurl,mhzz,mhjs,mhzt,mhfg,mhzj,wj,lz,mhzjid,zjurl,zjbody,zjsx,zjfy,zjtpurlsx,zjtpsl,zjtpsurl,zjtpurl,gxurl,gxbody,gxfg,gxmc,gxid ");
			strSql.Append(" FROM cjxm ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "cjxm";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

